<template>
  <el-drawer
    v-model="drawerVisible"
    :destroy-on-close="true"
    size="450px"
    :title="`${drawerProps.title}`"
  >
    <Form :schema="schema" ref="ruleFormRef" />
    <template #footer>
      <el-button @click="drawerVisible = false">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts" name="DepDrawer">
import { ref } from 'vue'
import { Form } from '@/components/Form'
import { schema } from '@/views/System/components/department/data'
interface DrawerProps {
  title: string
  //   isView: boolean
  rowData: { [key: string]: any }
  //   api?: (params: any) => Promise<any>
  //   getTableList?: () => void
}
const drawerVisible = ref(false)
const drawerProps = ref<DrawerProps>({
  //   isView: false,
  title: '',
  rowData: {}
})
// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params
  drawerVisible.value = true
}

// 提交数据（新增/编辑）
const ruleFormRef = ref()
const handleSubmit = () => {
  ruleFormRef.value!.validate(async (valid) => {
    if (!valid) return
    try {
    } catch (error) {
      console.log(error)
    }
  })
}
defineExpose({
  acceptParams
})
</script>
